﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FinalProject.Services.Interfaces;
using FinalProject.Data.EntityRepositories.Interfaces;
using FinalProject.Data.DBInteractions.Interfaces;
using FinalProject.Data.Search;
using FinalProject.Entities;

namespace FinalProject.Services.Services
{
    public class ChargeCategoryService : IChargeCategoryService
    {
        private readonly IChargeCategoryRepository _repository;
        private readonly IUnitOfWork _unitOfWork;
        public ChargeCategoryService(IChargeCategoryRepository repository, IUnitOfWork unitOfWork)
        {
            this._repository = repository;
            this._unitOfWork = unitOfWork;
        }

        #region Members

        public PagedListResult<Entities.ChargeCategory> GetAll()
        {
            var entities = _repository.Search(new SearchQuery<ChargeCategory>());
            return entities;
        }

        public Entities.ChargeCategory GetById(int id)
        {
            var chargeCategory = _repository.GetById(id);
            return chargeCategory;
        }

        public void Create(Entities.ChargeCategory chargeCategory)
        {
            _repository.Add(chargeCategory);
            _unitOfWork.Commit();
        }

        public void Update(Entities.ChargeCategory chargeCategory)
        {
            _repository.Update(chargeCategory);
            _unitOfWork.Commit();
        }

        public void Delete(int id)
        {
            var chargeCategory = _repository.GetById(id);
            _repository.Delete(chargeCategory);
            _unitOfWork.Commit();
        }

        public void Save()
        {
            _unitOfWork.Commit();
        }

        #endregion
    }
}
